package com.czk.ioc.benpostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * BeanPostProcessor，可以在spring容器实例化bean之后，在执行bean的初始化方法前后，添加一些自己的处理逻辑。这里说的初始化方法，指的是下面两种：
 * 1）bean实现了InitializingBean接口，对应的方法为afterPropertiesSet
 * <p>
 * 2）在bean定义的时候，通过init-method设置的方法
 * ————————————————
 *
 * @Author:ChenZhangKun
 * @Date: 2020/11/22 14:20
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("在初始化之前bean("+beanName+")传给postProcessBeforeInitialization处理了");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("在初始化之后bean("+beanName+")传给postProcessAfterInitialization处理了");
        return bean;
    }
}
